package com.example.demo.utils;

import java.io.Serializable;

/**
 * Created by Hy on 2018/8/23.
 * 前后端交互
 */
public class Result implements Serializable{
    /**
     * 状态码
     */
    private Integer code;
    /**
     * 信息
     */
    private String info;
    /**
     * 数据
     */
    private Object data;

    public static Result ok(String info,Object data) {
        return new Result(ResultEnum.OK.getCode(),info,data);
    }
    public static Result ok(){
        return ok(null,null);
    }
    public static Result error(Integer code,String info){return error(code,info,null);}

    public static Result error(Integer code,String info,Object data){return new Result(code,info,data);}

    public static Result error(ResultEnum resultEnum){return error(resultEnum,null);}

    public static Result error(ResultEnum resultEnum, Object data) {
        return error(resultEnum.getCode(), resultEnum.getInfo(),data);
    }
    public Result() {
    }

    public Result(Integer code, String info, Object data) {
        this.code = code;
        this.info = info;
        this.data = data;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getInfo() {
        return info;
    }

    public void setInfo(String info) {
        this.info = info;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return "Result{" +
                "code=" + code +
                ", info='" + info + '\'' +
                ", data=" + data +
                '}';
    }
}
